<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-radio-group v-model="queryParams.orderTab" @input="handleQuery">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button label="3">合约中</el-radio-button>
        <el-radio-button label="4">已退租</el-radio-button>
      </el-radio-group>
    </el-row>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="房源" prop="premisesAddress">
        <el-input
          v-model="queryParams.premisesAddress"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租住周期">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="orderState">
        <el-select
          v-model="queryParams.orderState"
          placeholder=""
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.order_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="orderList"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <el-table-column
        label="房源"
        prop="premisesAddress"
        :show-overflow-tooltip="false"
        width="250"
      />
      <el-table-column
        label="签约方式"
        prop=""
        :show-overflow-tooltip="true"
        width="150"
      >
        <template slot-scope="scope">
          {{ scope.row.lesseeType==1?'个人签约':'企业签约' }}
        </template>
      </el-table-column>
      <el-table-column label="入住日期" prop="checkInTime">
        <template slot-scope="scope">
          {{ scope.row.checkInTime|formatDate("YYYY-MM-DD") }}
        </template>
      </el-table-column>
      <el-table-column label="退租日期" prop="checkOutTime">
        <template slot-scope="scope">
          {{ scope.row.checkOutTime|formatDate("YYYY-MM-DD") }}
        </template>
      </el-table-column>
      <el-table-column label="入住人数" prop="memberNumber">
      </el-table-column>
      <el-table-column label="状态" prop="orderState">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.order_state"
            :value="scope.row.orderState"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="detailhandle(scope.row)"
            >人员信息</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 详情弹窗 -->
<!--    <order-detail-->
<!--      :open.sync="detailDialogVisible"-->
<!--      v-if="detailDialogVisible"-->
<!--      :orderId="orderId"-->
<!--    ></order-detail>-->
    <addPerson
      v-if="openAdd"
      v-model="openAdd"
      :order="orderInfo"
    ></addPerson>
  </div>
</template>

<script>
import { validList } from "@/api/order/order";
import addPerson from "./component/add-person.vue";
export default {
  name: "checkpersonList",
  dicts: [
    "order_state",
    "trading_mode",
    "order_tab",
  ],
  components: { addPerson },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 当前选择
      current: "",
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],

      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderTab: "",
        roomNumber: undefined,
        premisesAddress: undefined,
        status: undefined,
        orderState: undefined,
        orderIds: undefined,
        reserveUser: "",
        reserveUserPhone: "",
        orderSource: undefined,
        checkInTime: "",
        checkOutTime: "",
      },
      countHouseList: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        roomNumber: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
      detailDialogVisible: false,
      orderId: "",
      openAdd: false,
      openEdit: false,
      orderInfo: {},
      addDialogVisible: false, //新建弹窗，
      openmembershipRegistration: false,
      idEdit: false, //是否编辑成员
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    handleMembers(row) {
      this.isEdit = false;
      this.orderInfo = row;
      this.openmembershipRegistration = true;
    },
    editMembers(row) {
      this.isEdit = true;
      this.orderInfo = row;
      this.openmembershipRegistration = true;
    },
    dialogClose() {
      this.openAdd = false;
      this.openEdit = false;
      this.openmembershipRegistration = false;
      this.getList();
    },
    stateHandel(i) {
      this.queryParams.orderState = i;
      this.handleQuery();
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      this.queryParams.checkInTime = this.dateRange[0];
      this.queryParams.checkOutTime = this.dateRange[1];
      validList(this.queryParams, this.dateRange).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.orderId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.queryParams.orderIds = this.ids;
    },
    // 详情操作
    handleDetail(row) {
      this.orderId = row.orderId;
      this.detailDialogVisible = true;
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.orderInfo = row;
      this.openEdit = true;
    },
    //操作
    detailhandle(row) {
      this.orderInfo = row;
      this.openAdd = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "enterprise/order/order/export",
        {
          ...this.queryParams,
        },
        `订单_${new Date().getTime()}.xlsx`
      );
    },
    //请空选择项
    clearSelect() {
      this.$refs.table.clearSelection();
    },
  },
};
</script>
<style lang="scss" scoped>
.title {
  font-size: 14px;
  font-weight: 500;
  color: #666;
}
.total {
  font-size: 18px;
  font-weight: 500;
  color: #333;
  margin-top: 6px;
}
.left-border {
  border-left: 1px solid #999;
}
.right-border {
  border-right: 1px solid #999;
}
.info {
  padding: 10px 15px;
  margin: 15px 0;
  background: #e6f7ff;
  color: #1890ff;
  span {
    color: #565c5f;
  }
  .clear {
    margin-left: 20px;
    cursor: pointer;
  }
}
</style>
